package jdl.tokenization.states;

import java.util.Hashtable;
import java.util.List;

import jdl.tokenization.Token;
import jdl.tokenization.TokenType;

public class InitialState implements IState {
	private List<Token> tokens;
	private Hashtable<Character, TokenType> hashtable;
	private IState state;

	public InitialState(List<Token> tokens,
			Hashtable<Character, TokenType> hashtable) {
		this.tokens = tokens;
		this.hashtable = hashtable;
		state = this;
	}

	@Override
	public void analyzeSymbol(char symbol) {
		if (symbol == ' ')
			return;
		if (hashtable.get(symbol) == TokenType.NUMBER) {
			state = new NumberState(tokens, hashtable);
			state.analyzeSymbol(symbol);
		} else {
			if (!hashtable.containsKey(symbol)) {
				state = new WordState(tokens, hashtable);
				state.analyzeSymbol(symbol);
			} else {
				String content = new String(new char[] { symbol });
				TokenType tokenType = hashtable.get(symbol);
				tokens.add(new Token(content, tokenType));
			}
		}
	}

	@Override
	public IState getNextState() {
		return state;
	}

	@Override
	public void endOfSymbols() {

	}
}
